#include <iostream>
#include <list>
using namespace std;

struct Order {};

// the Receiver
class OrderService {
private:
	Order* order;
public:
	OrderService(Order* order) 
	{
		this->order = order;
	}
	void createOrder() 
	{
		cout << "create an order" << endl;
	}
	void modifyOrder() 
	{
		cout << "modify the order" << endl;
	}
	void deleteOrder() 
	{
		cout << "delete the order" << endl;
	}
};

class Command 
{
public:
	virtual ~Command() {}
	virtual void execute()=0;
};

class CreateCommand: public Command 
{
private:
	OrderService* service;
public:
	CreateCommand(OrderService* service) 
	{
		this->service = service;
	}
	void execute() 
	{
		this->service->createOrder();
	}
};

class ModifyCommand: public Command 
{
private:
	OrderService* service;
public:
	ModifyCommand(OrderService* service) 
	{
		this->service = service;
	}
	void execute() 
	{
		this->service->modifyOrder();
	}
};

class DeleteCommand: public Command 
{
private:
	OrderService* service;
public:
	DeleteCommand(OrderService* service) 
	{
		this->service = service;
	}
	void execute() {
		this->service->deleteOrder();
	}
};

class Invoker 
{
private:
	list<Command*> cmds;
public:
	void addCommand(Command* command) 
	{
		cmds.push_back(command);
	}
	void delCommand(Command* command) 
	{
		cmds.remove(command);
	}
	void action() 
	{
		for(list<Command*>::iterator iter=cmds.begin(); iter!=cmds.end(); iter++) 
		{
			(*iter)->execute();
		}
	}
};

int main() 
{
	OrderService* service = new OrderService(new Order());
	Invoker* invoker = new Invoker();
	invoker->addCommand(new CreateCommand(service));
	invoker->addCommand(new ModifyCommand(service));
	invoker->addCommand(new DeleteCommand(service));
	invoker->action();
	return 0;
}
